﻿using Mirror;
using TMPro;
using UnityEngine;
using Microsoft.MixedReality.Toolkit.UI;

namespace Shows_3D
{
    public class CustomServiceItem : MonoBehaviour
    {
        [SerializeField] private TextMeshPro buttonTitle;
        [SerializeField] private ButtonConfigHelper buttonConfigHelper;
        private string ButtonTitle
        {
            set => buttonTitle.text = value;
        }
        private Shows3DServerResponse _info;

        /// <summary>
        /// 初始化，绑定连接事件
        /// </summary>
        public void Init(Shows3DServerResponse info)
        {
            Debug.Log("init!");
            ButtonTitle = info.name;
            _info = info;
            buttonConfigHelper.OnClick.AddListener(Connect);
        }

        private void Connect()
        {
            //连接相应服务器
            NetworkSystem.Instance.connect(_info);
            //连接成功之后，修改 button 
            buttonConfigHelper.OnClick.RemoveListener(Connect);
            ConnectionManager.Instance.PostToFsm("connect", _info);
        }
    }
}